package com.example.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.params.SetParams;

import java.util.HashSet;
import java.util.Set;

/**
 * @Date: 2020/11/27 19:42
 * @Version: 1.0
 */

public class ConTest {
    /**
     *   <property name="maxWaitMillis" value="-1" />
     *         <property name="maxTotal" value="1000" />
     *         <property name="minIdle" value="8" />
     *         <property name="maxIdle" value="100" />
     */
    JedisCluster jedisCluster;
    JedisPoolConfig jedisPoolConfig;
    @Before
    public void bef(){
        jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxWaitMillis(-1);
        jedisPoolConfig.setMaxTotal(1000);
        jedisPoolConfig.setMinIdle(8);
        jedisPoolConfig.setMaxTotal(100);
        Set<HostAndPort> hosts = new HashSet<>();
        hosts.add(new HostAndPort("172.21.1.198",7001));
        hosts.add(new HostAndPort("172.21.1.198",7002));
        hosts.add(new HostAndPort("172.21.1.198",7003));
        hosts.add(new HostAndPort("172.21.1.198",6001));
        jedisCluster = new JedisCluster(hosts,jedisPoolConfig);
    }

    @Test
    public void test(){
    // 添加数据
        jedisCluster.set("user:name:01","zhangsan");
        //获取数据
        String s = jedisCluster.get("user:name:01");
        System.out.println(s);

        //删除数据
        jedisCluster.del("user:name:01");

    }

    @After
    public void close(){
        jedisCluster.close();
    }
}
